<?php

namespace Mogod\Core\Task;

/**
 *
 * Исполнитель
 *
 * @author goorus, morph
 *
 */
class TaskExecutor
{

	/**
	 * Менеджер сервисов
	 * @var \Mogod\Core\DependencyInjection\ServiceManager
	 */
	protected $serviceManager;

	/**
	 *
	 * @param \Mogod\Core\DependencyInjection\ServiceManager $serviceManager
	 */
	public function __construct(
		\Mogod\Core\DependencyInjection\ServiceManager $serviceManager)
	{
		$this->serviceManager = $serviceManager;
	}

	/**
	 * Выполняет задание
	 *
	 * @param TaskAbstract $task
	 * @return $this
	 */
	public function execute($task)
	{
		$worker = $this->serviceManager->get($task->getWorker(), $this);
		$worker->execute($task);
		return $this;
	}

}
